package 力扣日常刷题.木22二月.第01天206;

/**
 * @author 帅小伙
 * @date 2022/2/6
 * @description
 *    减半搜索
 */
public class Demo05JZ搜索二维矩阵2 {


    public boolean searchMatrix(int[][] matrix, int target) {
        if(matrix == null || matrix.length == 0 || matrix[0].length == 0) return false;

        int x = matrix.length,y = matrix[0].length;

        for (int i = 0; i < x; i++) {
            for (int j = 0; j < y && y > 0; j++) {
                if(matrix[i][j] == target) return true;
                else if(matrix[i][j] > target) y = j;
            }
        }
        return false;
    }

}
